package com.telecomyt.jwportal.activity.conversation;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.telecomyt.jwportal.R;
import com.telecomyt.jwportal.activity.conversation.adapter.ConversationDetailsAdapter;
import com.telecomyt.jwportal.activity.conversation.bean.CallInfoBean;
import com.telecomyt.jwportal.base.BaseActivity;
import com.telecomyt.jwportal.base.BasePresenter;
import com.telecomyt.jwportal.widget.FraToolBar;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @date: 2020/9/9
 * @author: chengDa
 * @description: 通话详情
 */
public class ConversationDetailsActivity extends BaseActivity {

    @BindView(R.id.mFraToolBar)
    FraToolBar mFraToolBar;
    @BindView(R.id.mTvNameAndPhone)
    TextView mTvNameAndPhone;
    @BindView(R.id.mRelativeLayout)
    RelativeLayout mRelativeLayout;
    @BindView(R.id.mRecyclerView)
    RecyclerView mRecyclerView;
    private String number;
    List<CallInfoBean> listBeans = new ArrayList<>();
    private ConversationDetailsAdapter conversationDetailsAdapter;

    public static void start(Context context, CallInfoBean data) {
        Intent starter = new Intent(context, ConversationDetailsActivity.class);
        starter.putExtra("data", data);
        context.startActivity(starter);
    }


    @Override
    protected int getLayoutId() {
        return R.layout.activity_conversation_details;
    }

    @Override
    protected void initView() {
        mFraToolBar.setLeftFinish(this);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        conversationDetailsAdapter = new ConversationDetailsAdapter(R.layout.fragment_conversation_details_items);
        mRecyclerView.setAdapter(conversationDetailsAdapter);
    }

    @Override
    protected void initData() {
        CallInfoBean data = (CallInfoBean) getIntent().getSerializableExtra("data");
        if (data == null) return;
        number = data.getNumber();
        if (TextUtils.isEmpty(data.getName())) {
            mTvNameAndPhone.setText(String.format("%s", number));
        } else {
            mTvNameAndPhone.setText(String.format("%s  %s", data.getName(), number));
        }
        listBeans.clear();
        listBeans.add(data);
        conversationDetailsAdapter.setNewData(listBeans);
    }

    @Override
    protected BasePresenter creatPresenter() {
        return null;
    }

    @OnClick(R.id.mRelativeLayout)
    public void onViewClicked() {
        Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + number));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }
}